package com.example.demo7;

import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Glow;
import javafx.stage.Stage;

public class StartScreen {
    private Scene scene;
    private ImageView backgroundView;
    private Button singlePlayerBtn;
    private Button twoPlayerBtn;
    private VBox menuBox;

    public StartScreen(Runnable onSinglePlayer, Runnable onTwoPlayer) {
        initialize(onSinglePlayer, onTwoPlayer);
    }

    private void initialize(Runnable onSinglePlayer, Runnable onTwoPlayer) {
        // 加载背景图片
        Image backgroundImage = new Image(getClass().getResourceAsStream("/千恋万花开始界面1.jpg"));
        backgroundView = new ImageView(backgroundImage);

        // 设置背景图片填充整个界面
        backgroundView.setFitWidth(1555);
        backgroundView.setFitHeight(972);


        // 创建标题文本
        Text title = new Text("美少女RPG冒险游戏");
        title.setFont(Font.font("YouYuan", FontWeight.BOLD, 56)); // 增大标题字号
        title.setFill(Color.PINK);
        title.setStroke(Color.PURPLE);
        title.setStrokeWidth(2);

        // 添加标题特效
        DropShadow shadow = new DropShadow();
        shadow.setColor(Color.PURPLE);
        shadow.setRadius(20); // 增大阴影效果
        shadow.setSpread(0.6);
        title.setEffect(shadow);

        Text subtitle = new Text("SenrenBanka");
        subtitle.setFont(Font.font("Monotype Corsiva", FontWeight.BOLD, 45)); // 增大副标题字号
        subtitle.setFill(Color.YELLOW);
        shadow.setRadius(10);
        shadow.setSpread(0.6);
        subtitle.setEffect(new Glow(0.9));

        // 创建按钮
        singlePlayerBtn = new Button("单人模式");
        twoPlayerBtn = new Button("双人模式");

        // 设置按钮字体和大小
        Font buttonFont = Font.font("Microsoft YaHei", FontWeight.BOLD, 32); // 增大按钮文字
        singlePlayerBtn.setFont(buttonFont);
        twoPlayerBtn.setFont(buttonFont);

        // 设置按钮样式
        String buttonStyle = "-fx-background-color: rgba(255, 182, 193, 0.7); " +
                "-fx-text-fill: #8B008B; " +
                "-fx-padding: 15 50; " + // 增大按钮内边距
                "-fx-border-color: #FF69B4; " +
                "-fx-border-width: 3; " +
                "-fx-border-radius: 20; " + // 增大圆角
                "-fx-background-radius: 20; " +
                "-fx-min-width: 300px;"; // 设置按钮最小宽度

        String hoverStyle = "-fx-background-color: rgba(255, 105, 180, 0.9); " +
                "-fx-text-fill: white; " +
                "-fx-effect: dropshadow(gaussian, #FF1493, 15, 0.6, 0, 0);"; // 增强悬停效果

        singlePlayerBtn.setStyle(buttonStyle);
        twoPlayerBtn.setStyle(buttonStyle);

        // 添加按钮悬停效果
        singlePlayerBtn.setOnMouseEntered(e -> singlePlayerBtn.setStyle(buttonStyle + hoverStyle));
        singlePlayerBtn.setOnMouseExited(e -> singlePlayerBtn.setStyle(buttonStyle));
        twoPlayerBtn.setOnMouseEntered(e -> twoPlayerBtn.setStyle(buttonStyle + hoverStyle));
        twoPlayerBtn.setOnMouseExited(e -> twoPlayerBtn.setStyle(buttonStyle));

        // 设置按钮点击事件
        singlePlayerBtn.setOnAction(e -> onSinglePlayer.run());
        twoPlayerBtn.setOnAction(e -> onTwoPlayer.run());

        // 创建菜单布局
        menuBox = new VBox(30, title, subtitle, singlePlayerBtn, twoPlayerBtn); // 增大元素间距
        menuBox.setAlignment(Pos.CENTER);

        // 计算居中位置
        double centerX = (1555 - 300) / 2.5;
        double centerY = (double) 972 / 3;

        // 使用Pane的自动居中布局
        Pane root = new Pane(backgroundView, menuBox);
        menuBox.setLayoutX(centerX);
        menuBox.setLayoutY(centerY);

        // 或者使用StackPane实现自动居中（推荐）
        // StackPane root = new StackPane(backgroundView, menuBox);

        scene = new Scene(root, 1555, 972);
    }

    public Scene getScene() {
        return scene;
    }
}